import * as THREE from '../lib/three.module';

const notFound = function (text = 'Model file not found') {
  const that = this;
  // 使用FontLoader加载字体
  const loader = new THREE.FontLoader();
  loader.load('./models/font.json', function (response) {
    // 文字配置
    const fontCfg = {
      font: response,
      size: 80,
      height: 25,
      curveSegments: 12,
      bevelEnabled: true,
      bevelThickness: 10,
      bevelSize: 8,
      bevelSegments: 5
    };
    // TextGeometry文本几何对象
    const fontGeometry = new THREE.TextGeometry(text, fontCfg);
    fontGeometry.computeBoundingBox(); // 绑定盒子模型

    // 文字的材质
    const fontMaterial = new THREE.MeshNormalMaterial();
    const font = new THREE.Mesh(fontGeometry, fontMaterial);

    // 计算出整个模型宽度的一半, 不然模型就会绕着x = 0,中心旋转
    font.position.x = -(fontGeometry.boundingBox.max.x - fontGeometry.boundingBox.min.x) / 2;

    that.scene.add(font);
  });
};

export default notFound;